import service from "./service/modelserService";
// import service from "./service";
import { getProjectManager } from "@/scripts/getProjectManager";
import loading from "./loading";

const getModelser2Ip = () => {
    const objm = getProjectManager()
    return objm.modelser2Manager.modelser2Url.match(/^(https?:\/\/[^\/]+)/)?.[1]
}


// 创建任务
export const reqCreateTask = (data: any) => {
    loading.showLoading("正在提交任务，请稍后...")
    const getInfoData = service({
        url: `${getModelser2Ip()}/ts/editor`,
        method: 'post',
        data
    })
    return getInfoData
}

// 随机获取一个Tile的范围
export const reqGetRandomTile = (tileServiceName: string) => {
    const getInfoData = service({
        url: `${getModelser2Ip()}/ts/datasetref/tile/bound?tileServiceName=${tileServiceName}`,
        method: 'get',
    })
    return getInfoData
}

// 编辑历史
export const reqGetHistory = (data: any) => {
    const getInfoData = service({
        url: `${getModelser2Ip()}/ts/editor/list`,
        method: 'post',
        data
    })
    return getInfoData
}

// 删除编辑历史
export const reqDeleteHistory = (data: any) => {
    loading.showLoading("正在删除编辑历史，请稍后...")
    const getInfoData = service({
        url: `${getModelser2Ip()}/ts/editor/delete`,
        method: 'post',
        data
    })
    return getInfoData
}

// 创建单体化
export const reqCreateMonomer = (data: any) => {
    loading.showLoading("正在创建单体化，请稍后...")
    const getInfoData = service({
        url: `${getModelser2Ip()}/ts/instance/create`,
        method: 'post',
        data
    })
    return getInfoData
}

// 根据经纬度获取单体化
export const reqGetMonomer = (data: any) => {
    const getInfoData = service({
        url: `${getModelser2Ip()}/ts/instance/getbycondition`,
        method: 'post',
        data
    })
    return getInfoData
}

// 获取单体化属性列表
export const reqGetMonomerProperty = (data: any) => {
    const getInfoData = service({
        url: `${getModelser2Ip()}/ts/instance/fields/list`,
        method: 'post',
        data
    })
    return getInfoData
}

// 获取单体化列表
export const reqGetInstanceList = (data: any) => {
    const getInfoData = service({
        url: `${getModelser2Ip()}/ts/instance/list`,
        method: 'post',
        data
    })
    return getInfoData
}

// 修改单体化
export const reqUpdateMonomer = (data: any) => {
    loading.showLoading("正在修改，请稍后...")
    const getInfoData = service({
        url: `${getModelser2Ip()}/ts/instance/update`,
        method: 'post',
        data
    })
    return getInfoData
}

// 删除单体化
export const deleteDantihua = (data = {}) => {
    loading.showLoading("正在删除，请稍后...")
    const deleteData = service({
        url: `${getModelser2Ip()}/ts/instance/delete`,
        method: 'post',
        data,
    })
    return deleteData
}


// 纹理列表
export const reqGetTexture = (data: any) => {
    const getInfoData = service({
        url: `${getModelser2Ip()}/lib/texture/list`,
        method: 'post',
        data
    })
    return getInfoData
}

// 切片服务列表
export const reqGetRecordList = (data: any) => {
    const getInfoData = service({
        url: `${getModelser2Ip()}/ts/record/list`,
        method: 'post',
        data
    })
    return getInfoData
}

// 上传shp
export const reqUploadShp = (data: any) => {
    const getInfoData = service({
        url: `${getModelser2Ip()}/system/file/upload/shp`,
        method: 'post',
        data,
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })
    return getInfoData
}

// 上传shp(zip格式)
export const reqUploadShpZip = (data: any) => {
    const getInfoData = service({
        url: `${getModelser2Ip()}/system/file/upload/shpzip`,
        method: 'post',
        data,
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })
    return getInfoData
}

// 获取shp中所有要素
export const reqGetShpFeatures = (data: any) => {
    const getInfoData = service({
        url: `${getModelser2Ip()}/system/file/shp/features`,
        method: 'post',
        data,
    })
    return getInfoData
}

// 上传shp（zip格式）
export const upShpZip = (data: any) => {
    const getInfoData = service({
        url: `${getModelser2Ip()}/system/file/upload/shpzip`,
        method: "post",
        data,
        headers: {
            "Content-Type": "multipart/form-data",
        },
    });
    return getInfoData;
};

// 上传shp
export const upShp = (data: any) => {
    const getInfoData = service({
        url: `${getModelser2Ip()}/system/file/upload/shp`,
        method: "post",
        data,
        headers: {
            "Content-Type": "multipart/form-data",
        },
    });
    return getInfoData;
};

// 获取所有裁剪区域
export const reqGetClipPolygon = (data: any) => {
    const getInfoData = service({
        url: `${getModelser2Ip()}/ts/clip/list?tileServiceName=${data}`,
        method: 'get',
    })
    return getInfoData
}

// 添加裁剪区域
export const reqCreateClipPolygon = (data: any) => {
    loading.showLoading("正在提交任务，请稍后...")
    const getInfoData = service({
        url: `${getModelser2Ip()}/ts/clip/create`,
        method: 'post',
        data,
    })
    return getInfoData
}

/**
 * 获取系统配置
 */
export const reqGetSetting = () => {
    const getInfoData = service({
        url: `${getModelser2Ip()}/system/setting/get`,
        method: 'get',

    })
    return getInfoData
}

/**
 * 获取静态服务列表
 */
export const reqGetModelLists = (data: any) => {
    const getInfoData = service({
        url: `${getModelser2Ip()}/tile/model/list`,
        method: 'post',
        data,
    })
    return getInfoData
}

/**
 * 断面分析接口
 */
export const reqGetDuanmian = (data: any) => {
    loading.showLoading("开始分析，请稍后...")
    const requestData = new URLSearchParams();
    requestData.append('param', JSON.stringify(data));
    const getInfoData = service({
        url: `${getModelser2Ip()}/fenxi/duanmian`,
        method: 'post',
        data: requestData, // 使用data而不是param
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    })
    return getInfoData
}

/**
 * 方量分析接口
 */
export const reqGetFangliang = (data: any) => {
    loading.showLoading("开始分析，请稍后...")
    const requestData = new URLSearchParams();
    requestData.append('param', JSON.stringify(data));
    const getInfoData = service({
        url: `${getModelser2Ip()}/fenxi/fangliang`,
        method: 'post',
        data: requestData, // 使用data而不是param
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    })
    return getInfoData
}

